<?php
/**
 * get stats by partner id
 *
 * @author     ben
 */
class getStatsChartAction  extends WacStatsAction
{
    public function execute($request)
    {
        $this->setLayout(false);
//        $this->getContext()->getConfiguration()->loadHelpers('Url');

//        $oneYearPeriodsWidth = '600';
//        $periods = $this->getPeriods($request, 'month');
//        $swfWidth = $oneYearPeriodsWidth * ceil(count($periods) / 12);
        $swfWidth = $request->hasParameter("swf_width") ? $request->getParameter("swf_width") : '800';
        $swfHeight = $request->hasParameter("swf_height") ? $request->getParameter("swf_height") : '400';

        $resultSet = array("items"=> array());
        $params = array('width'=>$swfWidth,
                        'height'=>$swfHeight,
//                        'module'=>'statistic',
//                        'action'=>'getStatsChartData',
                        'module'=>$request->getParameter("data_module"),   // e.g. 'statistic',
                        'action'=>$request->getParameter("data_action"),    // 'e.g. getStatsChartData',
                        'chart_type'=>$request->getParameter("chart_type"),
                        'start_day'=>$request->getParameter("start_day"),
                        'start_month'=>$request->getParameter("start_month"),
                        'start_year'=>$request->getParameter("start_year"),
                        'end_day'=>$request->getParameter("end_day"),
                        'end_month'=>$request->getParameter("end_month"),
                        'end_year'=>$request->getParameter("end_year"),
                  );
        $queryStr = http_build_query($params);
//        $resultSet["items"][] = array('content' => $this->getPartial("getStatsChartSuccess", $params));
        $resultSet["items"][] = array('content' => $this->getPartial("getStatsChart",
                array(
                'width'=>$swfWidth,
                'height'=>$swfHeight,
                'module'=>$request->getParameter("data_module"),
                'action'=>$request->getParameter("data_action"),
                "queryStr"=>$queryStr)));

        return OutputHelper::getInstance()->outputJsonOrTextFormat($resultSet, $this);
    }
}